﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Common;
using Model;
using System.Xml;
using Tencent;
namespace UI.message
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string appid = "wxef2c55ebada8928b";
            string aeskey = "3E5y3Y8OFWSmHvkNJdANdXKJc6qH7hoygs6qNHpg3FB";
            string token = "yixiaoke";

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Request.InputStream);
            string xml = xmlDoc.InnerXml;
            string postData = xml;

            string sMsg = "";//解密后的内容
            var msg = new WXBizMsgCrypt(token, aeskey, appid);
            int ret = msg.DecryptMsg(
            Request.QueryString["msg_signature"],
            Request.QueryString["timestamp"],
            Request.QueryString["nonce"],
            postData,
            ref sMsg);

            WeiXin wx = new WeiXin();
            dynamic obj = wx.ConvertJson(wx.XmlToJson(sMsg));

            BusinessInfo business=BusinessDAL.FindOneByUserName(obj.ToUserName);
            string ouropenid = OpenidDAL.FindOurOpenID(obj.FromUserName, business.AuthorizationAppID);
            if (obj.Event == "subscribe")
            {
                WxPayAPI.WxPayApi.CompanyPay(ouropenid, 30, "亿逍客T7发来的红包");
            }
            Response.Write("success");
        }
    }
}